package com.horus.entities.dao.hibernate;

import java.io.File;

import org.hibernate.HibernateException;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;

public class HibernateFactory {

	private static HibernateFactory hibernateFactory;
	private static SessionFactory sessionFactory;
	
	private HibernateFactory(){
		
		try{
		Configuration configuration = new Configuration();
		//File configFile = new File("resources/hibernate/hibernate.cfg.xml");
		//boolean b = configFile.exists();
		//configuration.configure(configFile);
		configuration.configure();
		
		sessionFactory = configuration.buildSessionFactory();
		}catch (HibernateException hibernateException) {
			System.out.println("NPE");
			// TODO: handle exception
		}catch(NullPointerException npe){
			System.out.println("NPE");
		}
		
	}
	
	// TODO: Validate scope is OK
	protected static SessionFactory getSessionFactory(){
		
		if(hibernateFactory == null){
			hibernateFactory = new HibernateFactory();
		}
		return sessionFactory;
	}

}
